package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description OrdersController
 * @Author 小平
 * @Date 2024-02-27 14
 */
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Api(tags = "管理端-订单接口")
@Slf4j
public class OrdersController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("订单分页")
    @GetMapping("/conditionSearch")
    public Result<PageResult> pages(OrdersPageQueryDTO dto){
        log.info("订单分页查询");
        PageResult pageResult = orderService.pageQuery(dto);
        return Result.success(pageResult);
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result updateStatus(@PathVariable Long id){
        orderService.updateStatus(id);
        return Result.success();
    }

    /**
     * 接单
     */
    @PutMapping("/confirm")
    public Result setstatus(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.setStatus(ordersConfirmDTO);
        return Result.success();
    }
    /**
     * 订单完成
     */
    @PutMapping("/complete/{id}")
    public Result setOver(@PathVariable Long id){
        orderService.setOver(id);
        return Result.success();
    }

    @ApiOperation("店铺端查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("店铺端根据订单id查询订单详情表:{}",id);

        OrderVO orderVO = orderService.getOrderDetailByid(id);
        return Result.success(orderVO);
    }


    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单:{}",ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     *
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }


    /**
     * 取消订单
     *
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }



}
